package logic

import (
	"context"
	"tieba/models/mysql"

	"tieba/tiebarpc/internal/svc"
	"tieba/tiebarpc/tiebarpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type TypeAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewTypeAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TypeAddLogic {
	return &TypeAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *TypeAddLogic) TypeAdd(in *tiebarpc.TypeAddRequest) (*tiebarpc.TypeAddResponse, error) {
	// todo: add your logic here and delete this line
	var typ = mysql.TieBaType{
		TypeName: in.TypeName,
		Number:   in.Number,
	}
	mysql.DB.Debug().Create(&typ)
	return &tiebarpc.TypeAddResponse{
		TypeId: int64(typ.ID),
	}, nil
}
